import java.util.*;
import java.util.stream.*;

public class Main {

    public static void dfs(
            List<Integer> nums,
            int index,
            int level,
            List<Integer> path,
            List<List<Integer>> subsets) {
        if (path.size() == level) {
            subsets.add(new ArrayList<>(path));
        }

        for (int i = index; i < nums.size(); i++) {
            path.add(nums.get(i));
            dfs(nums, i + 1, level, path, subsets);
            path.remove(path.size() - 1);
        }
    }

    public static String findSubsets(List<Integer> nums, String target) {
        List<Integer> smallNums = new ArrayList<>();
        List<Integer> largeNums = new ArrayList<>();

        for (Integer num : nums) {
            if (num < 4) {
                smallNums.add(num);
            } else {
                largeNums.add(num);
            }
        }

        List<List<Integer>> subsets = new ArrayList<>();
        int smallSize = smallNums.size();
        int largeSize = largeNums.size();

        if (target.equals("1")) {
            handleTarget1(smallNums, largeNums, smallSize, largeSize, subsets);
        } else if (target.equals("2")) {
            handleTarget2(smallNums, largeNums, smallSize, largeSize, subsets);
        } else if (target.equals("4")) {
            handleTarget4(smallNums, largeNums, smallSize, largeSize, subsets);
        } else if (target.equals("8")) {
            handleTarget8(smallNums, largeNums, smallSize, largeSize, subsets);
        }

        return subsets.toString();
    }

    public static void handleTarget1(List<Integer> smallNums,
                                     List<Integer> largeNums,
                                     int smallSize, int largeSize, List<List<Integer>> subsets) {
        if (smallSize == 1 || largeSize == 1) {
            if (smallSize == 1) dfs(smallNums, 0, 1, new ArrayList<>(), subsets);
            if (largeSize == 1) dfs(largeNums, 0, 1, new ArrayList<>(), subsets);
        } else if (smallSize == 3 || largeSize == 3) {
            if (smallSize == 3) dfs(smallNums, 0, 1, new ArrayList<>(), subsets);
            if (largeSize == 3) dfs(largeNums, 0, 1, new ArrayList<>(), subsets);
        } else if (smallSize == 2 || largeSize == 2) {
            if (smallSize == 2) dfs(smallNums, 0, 1, new ArrayList<>(), subsets);
            if (largeSize == 2) dfs(largeNums, 0, 1, new ArrayList<>(), subsets);
        } else if (smallSize == 4 || largeSize == 4) {
            if (smallSize == 4) dfs(smallNums, 0, 1, new ArrayList<>(), subsets);
            if (largeSize == 4) dfs(largeNums, 0, 1, new ArrayList<>(), subsets);
        }
    }

    public static void handleTarget2(List<Integer> smallNums,
                                     List<Integer> largeNums,
                                     int smallSize, int largeSize, List<List<Integer>> subsets) {
        if (smallSize == 2 || largeSize == 2) {
            if (smallSize == 2) dfs(smallNums, 0, 2, new ArrayList<>(), subsets);
            if (largeSize == 2) dfs(largeNums, 0, 2, new ArrayList<>(), subsets);
        } else if (smallSize == 4 || largeSize == 4) {
            if (smallSize == 4) dfs(smallNums, 0, 2, new ArrayList<>(), subsets);
            if (largeSize == 4) dfs(largeNums, 0, 2, new ArrayList<>(), subsets);
        } else if (smallSize == 3 || largeSize == 3) {
            if (smallSize == 3) dfs(smallNums, 0, 2, new ArrayList<>(), subsets);
            if (largeSize == 3) dfs(largeNums, 0, 2, new ArrayList<>(), subsets);
        }
    }

    public static void handleTarget4(List<Integer> smallNums,
                                     List<Integer> largeNums,
                                     int smallSize, int largeSize, List<List<Integer>> subsets) {
        if (smallSize == 4 || largeSize == 4) {
            if (smallSize == 4) subsets.add(smallNums);
            if (largeSize == 4) subsets.add(largeNums);
        }
    }

    public static void handleTarget8(List<Integer> smallNums,
                                     List<Integer> largeNums,
                                     int smallSize, int largeSize, List<List<Integer>> subsets) {
        if (smallSize == 4 && largeSize == 4) {
            subsets.add(Stream.concat(smallNums.stream(), largeNums.stream())
                    .collect(Collectors.toList()));
        }
    }

    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            List<Integer> nums = readIntegerList(scanner.nextLine());
            String target = scanner.next();
            System.out.println(findSubsets(nums, target));
        }
    }

    public static List<Integer> readIntegerList(String input) {
        return Arrays.stream(input.split("[\\[\\],\\s]"))
                .filter(str -> !str.isEmpty())
                .map(Integer::parseInt)
                .collect(Collectors.toList());
    }


}
